package cn.shyouchi.wuguanjia.android.widget.dialog;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.ui.event.labor.RankTime;

/**
 * Created by Eenie on 2016/10/28 at 16:54
 * Email: 472279981@qq.com
 * Des:
 */

public class LaborEditFragment extends DialogFragment {


    LaborDialogListener mLaborDialogListener;


    int normalCount = 0;
    int dayCount = 0;
    int nightCount = 0;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.rv_ranks)
    RecyclerView mRvRanks;
    @BindView(R.id.tv_count)
    TextView mTvCount;
    @BindView(R.id.basic_edit_dialog_cancel_button)
    Button mBasicEditDialogCancelButton;
    @BindView(R.id.basic_edit_dialog_confirm_button)
    Button mBasicEditDialogConfirmButton;


    LaborEditAdapter mLaborEditAdapter;
    List<RankTime.ResultMessageBean> mLaborEntities = new ArrayList<>();


//    public LaborEditFragment() {
//        Bundle b = new Bundle();
//        b.putCharSequence("label", "");
//        setArguments(b);
//    }

   public static LaborEditFragment newInstance(CharSequence label) {
        LaborEditFragment f = new LaborEditFragment();
        Bundle b = new Bundle();
        b.putCharSequence("label", label);
        f.setArguments(b);
        return f;
    }

//
//    public static ArrangeTimeSetDialog newInstance(
//            String title, String subtitle, String contentHint1, String contentHint2) {
//        ArrangeTimeSetDialog fragment = new ArrangeTimeSetDialog();
//        Bundle args = new Bundle();
//        args.putString(ARG_TITLE, title);
//        args.putString(ARG_SUBTITLE, subtitle);
//        args.putString(ARG_HINT_ONE, contentHint1);
//        args.putString(ARG_HINT_TWO, contentHint2);
//        fragment.setArguments(args);
//        return fragment;
//    }


//    public LaborEditFragment(List<RankTime.ResultMessageBean> mLaborEntities) {
//
//        this.mLaborEntities.addAll(mLaborEntities);
//
//    }

    public void setData(List<RankTime.ResultMessageBean> mLaborEntities) {
        this.mLaborEntities.addAll(mLaborEntities);
        for (RankTime.ResultMessageBean b : mLaborEntities) {
            b.setChecked(false);
            b.setCount(0);
            break;
        }

    }


    public void setLaborDialogListener(LaborDialogListener laborDialogListener) {
        mLaborDialogListener = laborDialogListener;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        View v = inflater.inflate(R.layout.dialog_fragment_labor_layout, container, false);
        ButterKnife.bind(this, v);
        mLaborEditAdapter = new LaborEditAdapter(mLaborEntities);
        mRvRanks.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvRanks.setAdapter(mLaborEditAdapter);


        return v;
    }


//    public int calculate() {
//        int count = 0;
//        if (mCkNormalWork.isChecked()) {
//            if (!TextUtils.isEmpty(mEditNormalCount.getText())) {
//
//                normalCount = Integer.parseInt(mEditNormalCount.getText().toString());
//                count = count + Integer.parseInt(mEditNormalCount.getText().toString()) * 8;
//            } else {
//                normalCount = 0;
//            }
//        }
//        if (mCkDayWork.isChecked()) {
//            if (!TextUtils.isEmpty(mEditDayCount.getText())) {
//                dayCount = Integer.parseInt(mEditDayCount.getText().toString());
//                count = count + Integer.parseInt(mEditDayCount.getText().toString()) * 12;
//            }else {
//                dayCount = 0;
//            }
//        }
//        if (mCkNightWork.isChecked()) {
//            if (!TextUtils.isEmpty(mEditNightCount.getText())) {
//                nightCount = Integer.parseInt(mEditNightCount.getText().toString());
//                count = count + Integer.parseInt(mEditNightCount.getText().toString()) * 12;
//            } else {
//                nightCount = 0;
//            }
//        }
//
//        tvCount.setText(String.format("总工时%d小时", count));
//        return count;
//    }


    @OnClick({R.id.basic_edit_dialog_cancel_button, R.id.basic_edit_dialog_confirm_button})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.basic_edit_dialog_cancel_button:


                dismiss();
                break;
            case R.id.basic_edit_dialog_confirm_button:
                if (mLaborDialogListener != null) {
                    mLaborDialogListener.onDialogPositiveClick(mLaborEditAdapter.getSelData());
                }
                dismiss();
                break;
        }
    }

//    @OnClick({R.id.basic_edit_dialog_cancel_button, R.id.basic_edit_dialog_confirm_button})
//    public void onClick(View view) {
//        switch (view.getId()) {
//            case R.id.basic_edit_dialog_cancel_button:
//                break;
//            case R.id.basic_edit_dialog_confirm_button:
//                break;
//        }
//    }

    public interface LaborDialogListener {
        void onDialogPositiveClick(List<RankTime.ResultMessageBean> mLaborEntities);

    }


}
